package com.example.bond_svc.service;

// 基础类导入
import java.time.LocalDateTime;

// 领域模型类导入（假设模型类在model包）
import com.example.bond_svc.model.BidRequest;
import com.example.bond_svc.model.BidResult;
import com.example.bond_svc.model.Auction;

// 仓储层接口导入（假设repository包存在）
import com.example.bond_svc.reposity.AuctionRepository;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AuctionService {
    private final AuctionRepository auctionRepository;

    public AuctionService(AuctionRepository auctionRepository) {
        this.auctionRepository = auctionRepository;
    }

    @Transactional
    public BidResult processBid(Long auctionId, BidRequest request) {
        Auction auction = auctionRepository.findById(auctionId)
                .orElseThrow(() -> new RuntimeException("拍卖不存在"));

        if (auction.getStatus() != Auction.Status.OPEN) {
            return new BidResult(auctionId, "拍卖已关闭", LocalDateTime.now());
        }

        if (request.getPrice() < auction.getFloorPrice()) {
            return new BidResult(auctionId, "出价低于底价", LocalDateTime.now());
        }

        // 实际业务逻辑（此处简化为直接返回成功）
        return new BidResult(auctionId, "投标成功", LocalDateTime.now());
    }
}